<?php

namespace app\v1\model;

use think\Model;
use think\Db;

/**
 * Class Campus
 * @package app\v1\model
 * 功能模块对应说明：该类对应微信端校区模块，校区模块相关的数据在这里面处理
 */
class Campus extends Base
{
    /**
    获取学校的信息接口
     */
    public function getCampusInfo()
    {
        $userInfo=getUserInfo();
        $user=model('v1/User');
       // $educationInfo=$user->getEducationInfo($userInfo['childId']);
        $educationInfo=$this->getShopInfo($userInfo['schoolId']);
        $data=array();
        $data['bannerList']=$educationInfo['campusimg']?explode(',',$educationInfo['campusimg']):array();
        $childInfo=$user->getCommonInfo($userInfo['childId'],$userInfo['orgId'],$userInfo['schoolId']);
        $data['school']=$childInfo['school'];
        $data['orgName']=$childInfo['orgName'];
        $data['shopIntroduce']=$educationInfo['desc'];
        $data['address']=$educationInfo['address'];
        $data['envInfo']=$educationInfo['environment']?explode(',',$educationInfo['environment']):array();
        $data['envCount']=count($data['envInfo']);
        $data['envInfo']=array_slice($data['envInfo'],0,6);
        $data['licenceInfo']=$educationInfo['licence']?explode(',',$educationInfo['licence']):array();
        $data['teacherList']=$this->getCampusTeacherList($userInfo['schoolId']);
        renderData(0,'ok',$data);

    }

    //获取机构环境列表
    public function getEnvPicList(){
        $userInfo=getUserInfo();
        $educationInfo=$this->getShopInfo($userInfo['schoolId']);
        $envList=$educationInfo['environment']?explode(',',$educationInfo['environment']):array();
        $totalPage=count($envList);
        $offset=($this->currentPage-1)*$this->pageCount;
        $list=array_slice($envList,$offset,$this->pageCount);
        $data=array('current_page'=>$this->currentPage,'envList'=>$list);
        renderData(0,'ok',$data);
    }

    //获取学校信息
    public function getShopInfo($schoolId){
        $map['effect']=1;
        $map['active']=1;
        $map['id']=$schoolId;
        $shopInfo=Db::name('Shop')->where($map)->find();
        return $shopInfo;
    }

    /**
     * 获取校区轮播图
     */
    public function getTopPic($schoolId){

    }
    //获取学校对应的教师列表
    public function getCampusTeacherList($schoolId,$current_page=1,$page_count=5){
//        $map['sur.shop_id']=$schoolId;
//        $map['sur.effect']=1;
//        $map['sur.active']=1;
//        $map['sur.type']=0;
        $map[]=['sur.shop_id','=',$schoolId];
        $map[]=['sur.effect','=',1];
        $map[]=['sur.active','=',1];
        $map[]=['sur.is_walla','=',0];
      //  $map[]=['sur.type','>',0];
        $teacherList=Db::name('Shop_user_relation')->alias('sur')->join('users u','sur.user_id=u.id')->where($map)->field('u.id as teacherId,u.headimgurl as avatar,u.name as teacherName,sur.desc')->limit($page_count)->page($current_page)->select();
//       echo Db::getLastSql();
//       die;
        return $teacherList;
    }

    //获取具体的教师列表
    public function getTeacherList(){
        $userId=$this->userId;
        $redis=getRedis();
        $userInfo=$redis->get(config('user_flag').$userId);
        $teacherList=$this->getCampusTeacherList($userInfo['schoolId'],$this->currentPage,$this->pageCount);
        $data=array('current_page'=>$this->currentPage,'teacherList'=>$teacherList);
        renderData(0,'ok',$data);

    }
}
